package only.level5.railgun.ysartifactsimulation.task;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import only.level5.railgun.ysartifactsimulation.Bean.ArtifactData;
import only.level5.railgun.ysartifactsimulation.Bean.CalcData;
import only.level5.railgun.ysartifactsimulation.publisher.ArtifactInfoPublisher;
import only.level5.railgun.ysartifactsimulation.utils.ArtifactUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;


@Component
public class DataPushTask {
    private static final ObjectMapper mapper = new ObjectMapper();

    @Autowired
    ArtifactInfoPublisher artifactInfoPublisher;

    @Scheduled(fixedRate = 1000)
    public void publishWatchTimes() throws JsonProcessingException {
        ArtifactData artifactData = new ArtifactData();
        artifactData.setFlowerList(ArtifactUtils.FLOWER_LIST);
        artifactData.setPlumList(ArtifactUtils.PLUME_LIST);
        artifactData.setEonList(ArtifactUtils.EON_LIST);
        artifactData.setCircletList(ArtifactUtils.CIRCLET_LIST);
        artifactData.setGobletList(ArtifactUtils.GOBLET_LIST);

        publishArtifact(artifactData);
    }


    public void publishArtifact(ArtifactData artifactData) throws JsonProcessingException {
        String message = mapper.writeValueAsString(artifactData);
        artifactInfoPublisher.sendData(message);
    }
}
